<template>
  <a-drawer
    :title="title"
    placement="right"
    :closable="true"
    :width="width"
    :visible="visible"
    @close="handleCancel"
    destroyOnClose
  >
    <a-tabs type="card">
      <a-tab-pane key="1" tab="盘点订单信息">
        <check-order-info-tab ref="checkOrderInfoTab" :record="model"></check-order-info-tab>
      </a-tab-pane>
      <a-tab-pane key="2" tab="订单材料信息">
        <check-material-info-tab ref="checkMaterialInfoTab" :materialData="materialData" :record="model"></check-material-info-tab>
      </a-tab-pane>
    </a-tabs>
  </a-drawer>

  <!--<j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :footer="null"
    switchFullscreen
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <div>
      <a-row>
        <a-col :span="5">
          <span style="font-weight: bold">盘点编号：</span>{{model.checkNo}}
        </a-col>
        <a-col :span="5">
          <span style="font-weight: bold">盘点时间：</span>{{model.createTime}}
        </a-col>
        <a-col :span="5">
          <span style="font-weight: bold">盘点仓库：</span>{{model.checkDepository == null ? "无": model.checkDepository}}
        </a-col>
        <a-col :span="5">
          <span style="font-weight: bold">盘点状态：</span>{{this.statusValue}}
        </a-col>
        <a-col :span="4">
          <span style="font-weight: bold">盘点人：</span>{{model.createBy}}
        </a-col>
      </a-row>
    </div>

    <div style="margin-top: 15px;margin-bottom: 10px">
      <a-row>
        <a-col :span="17">
          <span style="font-weight: bold">备注：</span>{{model.remark == null || model.remark == "" ? "无":model.remark}}
        </a-col>
        <a-col :span="7">
          <a-button type="primary" icon="download" @click="leadingOut">导出Excel</a-button>
          <a-button style="margin-right: 10px;margin-left: 10px" type="primary" v-if="model.checkStatus == 2" @click="createOtherInDepositoryOrder">生成盘盈单</a-button>
          <a-button type="primary" v-if="model.checkStatus == 2" @click="createOtherOutDepositoryOrder">生成盘亏单</a-button>
        </a-col>
      </a-row>
    </div>

    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        class="j-table-force-nowrap"
        bordered
        :data-source="materialData"
        :columns="columns"
        :pagination="false"
        :rowKey="(record,index)=>{return index}"
      >
      </a-table>
      <div style="font-size: 18px;margin-top: 10px;padding-bottom: 20px">
        <div style="float: left">合计：</div>
        <div v-for="(item,index) in materialData" :key="index" style="float:left;">
          <div v-if="item.checkResult > 0" style="margin-right: 20px">盘盈: <span style="color: #2eabff">{{item.checkResult}}</span></div>
          <div v-if="item.checkResult == 0" style="margin-right: 20px">正常: <span>{{item.checkResult}}</span></div>
          <div v-if="item.checkResult < 0" style="margin-right: 20px">盘亏: <span style="color: red">{{item.checkResult}}</span></div>
        </div>
      </div>
    </div>
  </j-modal>-->
</template>

<script>
  import { getAction, postAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import checkMaterialInfoTab from "./tab/checkMaterialInfoTab";
  import checkOrderInfoTab from "./tab/checkOrderInfoTab";

  export default {
    name: 'checkDetailModal',
    components: {
      checkMaterialInfoTab,
      checkOrderInfoTab
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },

    data() {
      return {
        materialData: [],
        columns: [
          {
            title: '名称',
            dataIndex: 'materialName',
            width: '13%',
            align: "center",
            slots: { title: 'customTitle' },
            scopedSlots: { customRender: 'materialName' },
            customRender:function (text) {
              return (text === null || text === ''|| text === '-') ? "-" : text
            }
          },
          {
            title: '型号',
            dataIndex: 'modelNumber',
            width: '12%',
            align: "center",
            scopedSlots: {customRender: 'modelNumber'},
            customRender:function (text) {
              return (text === null || text === ''|| text === '-') ? "-" : text
            }
          },
          {
            title: '规格',
            dataIndex: 'specifications',
            width: '13%',
            align: "center",
            scopedSlots: {customRender: 'specifications'},
            customRender:function (text) {
              return (text === null || text === ''|| text === '-') ? "-" : text
            }
          },
          {
            title: '品牌',
            dataIndex: 'brand',
            width: '12%',
            align: "center",
            scopedSlots: {customRender: 'brand'},
            customRender:function (text) {
              return (text === null || text === ''|| text === '-') ? "-" : text
            }
          },
          {
            title: '单位',
            dataIndex: 'unit',
            width: '5%',
            align: "center",
          },
          {
            title: '市场价',
            dataIndex: 'marketPrice',
            width: '5%',
            align: "center",
            scopedSlots: {customRender: 'marketPrice'},
            customRender:function (text) {
              return (text === null || text === ''|| text === '-') ? "-" : text + "元"
            }
          },
          {
            title: '预算价',
            dataIndex: 'estimatedCost',
            width: '5%',
            align: "center",
            scopedSlots: {customRender: 'estimatedCost'},
            customRender:function (text) {
              return (text === null || text === '' || text === '-') ? "-" : text + "元"
            }
          },
          {
            title: '系统数量',
            dataIndex: 'stock',
            width: '5%',
            align: "center",
            scopedSlots: {customRender: 'stock'},
          },
          {
            title: '盘点数量',
            dataIndex: 'checkNum',
            width: '5%',
            align: "center",
            scopedSlots: {customRender: 'checkNum'},
          },
          {
            title: '盘盈盘亏',
            dataIndex: 'checkResult',
            width: '5%',
            align: "center",
            scopedSlots: {customRender: 'checkResult'},
          },
          {
            title: '备注',
            dataIndex: 'remark',
            width: '12%',
            align: "center",
            scopedSlots: {customRender: 'remark'},
            customRender:function (text) {
              return (text == null || text === '') ? "无" : text
            }
          },
        ],
        title: '',
        width: '100%',
        visible: false,
        disableSubmit: false,
        fullscreen: true,
        model: {},
        statusValue:"",
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },
        url: {
          queryCheckItemList: "/ghSupplychainCheckItem/list",
          createOtherInDepositoryOrderUrl: "/ghSupplychainCheck/createOtherInDepositoryOrder",
          createOtherOutDepositoryOrderUrl: "/ghSupplychainCheck/createOtherOutDepositoryOrder",
          exportXlsUrl: "/ghSupplychainPurchaseOrder/exportXls",
          importExcelUrl: "/ghSupplychainPurchaseOrder/importExcel",
        }
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      },
    },
    created() {

    },
    methods: {
      //生成盘盈单
      createOtherInDepositoryOrder(){
        let inDepositoryArr = [];
        for (let i=0;i<this.materialData.length;i++){
          if (this.materialData[i].checkResult > 0){
            inDepositoryArr.push(this.materialData[i]);
          }
        }
        if (inDepositoryArr.length == 0){
          this.$message.error("盘点单中不存在盘盈材料");
          return;
        }
        this.model.checkItemVos = inDepositoryArr;
        postAction(this.url.createOtherInDepositoryOrderUrl,this.model).then(res=>{
          if (res.success) {
            this.$message.success(res.message);
            this.$emit('ok');
            this.close();
          }else {
            this.$message.error(res.message);
          }
        })
      },
      //生成盘亏单
      createOtherOutDepositoryOrder(){
        let outDepositoryArr = [];
        for (let i=0;i<this.materialData.length;i++){
          if (this.materialData[i].checkResult < 0){
            outDepositoryArr.push(this.materialData[i]);
          }
        }
        if (outDepositoryArr.length == 0){
          this.$message.error("盘点单中不存在盘亏材料");
          return;
        }
        this.model.checkItemVos = outDepositoryArr;
        postAction(this.url.createOtherOutDepositoryOrderUrl,this.model).then(res=>{
          if (res.success) {
            this.$message.success(res.message);
            this.$emit('ok');
            this.close();
          }else {
            this.$message.error(res.message);
          }
        })
      },

      getCheckStatusValue(status){
        switch (status) {
          case 1:
            this.statusValue = "草稿"
            return "草稿"
          case 2:
            this.statusValue = "盘点完成"
            return "盘点完成"
        }
      },
      showDetail(record) {
        this.getCheckStatusValue(record.checkStatus)
        this.model = Object.assign({}, record);
        this.model.statusValue = this.statusValue;
        getAction(this.url.queryCheckItemList, {id: record.id}).then((res) => {
          if (res.success) {
            this.materialData = res.result.records || res.result;
          }
        })
        this.visible = true;
      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleCancel() {
        this.close()
      },
    }
  }
</script>
<style scoped>
  .editable-row-operations a {
    margin-right: 8px;
  }

  .tableHiddle {
    display: none;
  }
</style>